package cn.iot.controller.sys;

import cn.iot.common.dto.ResultMsg;
import cn.iot.sys.entity.SysDevice;
import cn.iot.util.FacialInfo;
import com.netsdk.demo.module.GateModule;
import com.netsdk.demo.module.LoginModule;
import com.netsdk.lib.ToolKits;
import com.sun.jna.Memory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("/sys/device")
public class SysFaceController {

    /**
     * 录入人脸信息
     * @param args
     */
    public static void main(String[] args) {
        // 必须调用，否则登录失败
        LoginModule.init(null, null);
        try {
            // 登录
            boolean isLogin = LoginModule.login("192.168.1.198", 37777, "admin", "Admin123456");
            // 读取图片
            Memory memory = ToolKits.readPictureFile("D:\\IDEA\\毕业项目\\iot-manage-main\\upload\\zhou.jpg");
            // 人员信息 状态：0 其他刷脸状态错误
            GateModule.insertCard("1112","1112","zhou","123456",0,-1,9999,1,1,"2024-10-30 17:03:10","2024-11-30 17:03:10");
            // 人脸信息
            GateModule.addFaceInfo("1112", memory);


        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            // 退出登录
            LoginModule.logout();
        }
    }


    /**
     * 订阅
     * @return
     */
    @PostMapping("subscribe")
    public ResultMsg subscribe(@RequestBody SysDevice sysDevice) throws UnsupportedEncodingException {
        FacialInfo facialInfo = new FacialInfo();
        ResultMsg msg = facialInfo.subscribe(sysDevice);
        return msg;
    }

}
